package java51_0607;

import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

//3：把 1-10000内的所有质数 写入一个data.txt中，10个一行

public class PrimeTest {

	public static void main(String[] args) {
		DataOutputStream dain = null;
		try {
			dain = new DataOutputStream(new FileOutputStream("D:\\data.txt"));
			int i, a;
			int count = 0;
			for (i = 2; i <= 10000; i++) {
				for (a = 2; a * a < i; a++) {
					if (i % a == 0) {
						break;
					}
				}
				if (a * a > i) {
					// System.out.println(i);
					dain.writeInt(i);
					count++;
					if (count == 10) {
						dain.writeBytes("\r\n");
					}
				}

			}
			System.out.println("写入完成");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (dain != null)
				try {
					dain.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}

	}

}
